<template>
    <section class="newsMain">
      <div class="topTitle blue getTop">
        <span class="goBack" @click="goBack"><i></i></span>
        我送出的礼物
      </div>
      <div class="listA" v-if="dataList!=''">
        <ul>
          <li v-for="item in dataList">
            <img :src="item.gift.image">
            <div class="listLeft">
              <p class="name">{{item.gift.name}}</p>
              <p class="span">爱情币：{{item.gift.price}}</p>
            </div>
            <div class="listRight">
              <p class="time">{{item.updated_at|timeFilt}}</p>
              <p class="meili">魅力值：{{item.amount}}</p>
            </div>
          </li>
        </ul>
        <p class="loadMore" v-if="loadStatic">加载中...</p>
        <p class="noMore" v-else>-------- 我们是有底线的 --------</p>
      </div>
      <div class="listNone" v-else>
        没有数据
      </div>

    </section>
</template>
<style>
  .mint-loadmore-content ul li{height: 1rem;line-height: 1rem}
  .mint-tabbar{position: relative;}
  .mint-actionsheet{z-index: 10}
</style>
<script>
import axios from 'axios'
import {Post,Get} from '@/config/api.js'

export default {
  name: 'hello',
  data() {
    return {
      name: '',
      password: '',
      dataList:[],
      loadStatic:true,//加载状态
      onPage:1,//当前页面
      allDataPage:'',//总页数
    }
  },
  watch:{
    selected:function(){
      this.active=this.selected
    }
  },
  methods:{
    async getData(val){
      await Get('/gift/send?_include=gift,receive_user&page='+val,this.$store.state.token).then((res)=>{
        this.dataList.push(...res.data)
        this.allDataPage=res.meta.pagination.total_pages
      })
    },
    //返回上一页
    goBack(){
      this.$router.go(-1)
    },
    //下拉加载更多
    getSet(){
      let that=this
      $(window).scroll(function(){ 
          var h=$(document.body).height();//网页文档的高度 
          var c = $(document).scrollTop();//滚动条距离网页顶部的高度 
          var wh = $(window).height(); //页面可视化区域高度
           if (Math.ceil(wh+c)>=h){ 
              if(that.onPage<that.allDataPage){
                that.onPage++
                that.getData(that.onPage)
              }else{
                that.loadStatic=false
              }
          } 
      }) 
    },
    shopSet(){
      $(window).unbind('scroll');
    },
  },
  created: function () {
  },
  mounted: function () {
    this.getData(1)
    this.getSet()
  },
  activated: function () {
    console.log(3)
  },
  deactivated: function () {
    console.log(4)
    this.shopSet()
  },
  beforeDestroy(){
    this.shopSet()
  }
}

</script>
